{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>机构活动列表</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div  class="col-sm-3">
                        <div class="input-group" >
                            <a href="{:url('add')}">
                                <button type="button" class="btn btn-primary btn-outline"  >
                                    <i class="fa fa-plus"></i> 发布活动
                                </button>
                            </a>
                            <!--<button  class="btn btn-outline btn-danger" href="javascript:;" data-toggle="dropdown">-->
                            <!--<i class="fa fa-wrench"></i> 批量操作 <span class="caret"></span>-->
                            <!--</button>-->
                            <!--<ul class="dropdown-menu animated fadeInDown" role="menu">-->
                            <!--&lt;!&ndash;<li><a href="javascript:;" class="layuiBtn" id="empty" data-type="reload"><i class="fa fa-retweet"></i> 重置搜索框 </a></li>&ndash;&gt;-->
                            <!--<li><a href="javascript:;" class="layuiBtn" data-type="getCheckData"><i class="fa fa-trash-o"></i> 批量删除 </a></li>-->
                            <!--</ul>-->
                        </div>
                    </div>
                    <div class="col-sm-9">
                        <form id="layuiForm">
                            <div class="col-sm-5">
                                <div class="input-group" >
                                    <input type="text"  name="start" onclick="laydate({istime: true,format: 'YYYY-MM-DD hh:mm'})" class="form-control layer-date search" placeholder="活动发布日期" />
                                    <span class="input-group-addon">到</span>
                                    <input type="text"  name="end" onclick="laydate({istime: true,format: 'YYYY-MM-DD hh:mm'})"  class="form-control layer-date search" placeholder="活动发布日期" />
                                </div>
                            </div>
                            <div class="col-sm-2 form-group">
                                <select  class="form-control m-b chosen-select search" name="activity_status" id="my_activity_status">
                                    <option  value="">全部活动状态</option>
                                    <option  value="1">未开始</option>
                                    <option  value="2">报名中</option>
                                    <option  value="3">进行中</option>
                                    <option  value="4">结束</option>
                                </select>
                            </div>
                            <div class="col-sm-2 form-group">
                                <select  class="form-control m-b chosen-select search" name="my_activity_sh" id="my_activity_sh">
                                    <option  value="">全部审核状态</option>
                                    <option  value="1">审核通过</option>
                                    <option  value="2">审核驳回</option>
                                    <option  value="3">未审核</option>
                                </select>
                            </div>
                            <div class="col-sm-4">
                                <div class="input-group" >
                                    <input type="text" id="key" class="form-control search" name="key" value="" placeholder="机构名字|活动名字"/>
                                    <span class="input-group-btn">
                                        <a  class="btn btn-primary layuiBtn" data-type="reload"><i class="fa fa-search"></i> 搜索</a>
                                    </span>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Activity/index")}'
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            // ,width:100
            , cellMinWidth: 80
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , text: {
                none: '暂无数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {type:'numbers', width: 60, title: '序号'}
                , {field: 'id', width: 60, title: 'ID', sort: true, align: 'center'}
                , {field: 'activity_name', width: 130, title: '标题', align: 'center'}
                , {field: 'activity_img', width: 130, title: '活动图片', align: 'center',templet:"#imgTpl"}
                , {field: 'num', width: 130, title: '报名人数', align: 'center'}
                , {field: 'activity_address', width: '', title: '地址', align: 'center'}
                , {field: 'activity_label', width: '', title: '活动标签', align: 'center'}
                , {field: 'mechanism_name', width: 130, title: '发布机构', align: 'center'}
                , {field: 'activity_time', width: 130, title: '公益时长', align: 'center'}
                , {field: 'create_time', width: 130, title: '发布时间', align: 'center',templet:"#detail_type"}
                , {field: 'activity_sh', width: 130, title: '状态', align: 'center',templet:"#activity_sh"}
                , {field: 'activity_status', width: 130, title: '活动状态', align: 'center',templet:"#activity_status"}
                , {fixed: 'right', width: 200, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $.each(res.data,function(index,item){
                    $('#view_'+item['banner_id']).viewer({
                        url: 'data-original',
                    });
                });
            }
        });
        //监听状态开关操作
//        form.on('switch(OnOff)', function (obj) {
//            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
//            if(obj.elem.checked == true){
//                var num = 1;
//            }else{
//                var num = 2;
//            }
//            //用户状态
//            wk.status(this.value,num, '{:url("user_state")}');
//        });
        //搜索表格重载
        var $ = layui.$, active = {
            reload: function () {
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where:$('#layuiForm').parseForm()
                });
            }
//            ,getCheckData: function(){
//                //批量删除
//                wk.batchDel(getIds(),"{:url('batchDelBanner')}");
//            }
//            ,forbiddenAll: function(){
//                //批量禁用
//                wk.batchForbidden(getIds(),2,"{:url('forbiddenAdmin')}");
//            }
//            ,usingAll: function(){
//                //批量启用
//                wk.usingAll(getIds(),1,"{:url('usingAdmin')}");
//            }
//            ,excelAll: function(){
//                //导出Excel
//                wk.excelAll(getIds(),$('#layuiForm').serialize(),"{:url('excelAdmin')}");
//            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['id'])
            });
            return ids;
        }
    });
</script>
<!--操作模板-->
<script type="text/html" id="opeBar">
    {{# if(d.activity_sh==3){ }}
    <a href="javascript:location.href = '{:url('examine')}?id={{d.id}}';" class="btn btn-primary btn-outline btn-xs"><i class="fa fa-paste"></i> 审核</a>&nbsp;
    {{# } }}
    {{#  if(d.activity_status==1){ }}
    <a href="javascript:location.href = '{:url('update')}?id={{d.id}}';" class="btn btn-primary btn-outline btn-xs"><i class="fa fa-paste"></i> 编辑</a>&nbsp;

    {{# } }}
    {{#  if(d.activity_status==2){ }}
    <a href="javascript:location.href = '{:url('member')}?id={{d.id}}';" class="btn btn-danger btn-outline btn-xs"><i class="fa fa-paste"></i> 成员</a>
    {{# } }}
    <a href="javascript:location.href = '{:url('detail')}?id={{d.id}}';" class="btn btn-danger btn-outline btn-xs"><i class="fa fa-paste"></i> 查看</a>

</script>

<script type="text/html" id="imgTpl">
    <ul onclick="view(this)" id="view_{{d.id}}">
        <li><img data-original="{{d.activity_img}}" src="{{d.activity_img}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  /></li>
    </ul>
</script>
<script type="text/html" id="activity_sh">
    {{# if(d.activity_sh == 1){ }}
    <span style="color:#ec4758">审核通过</span>

    {{# }else if(d.activity_sh == 2){ }}
    <span style="color:#ec4758">未通过</span>
    {{# } else {}}
    <span style="color:#ec4758">未审核</span>
    {{# } }}
</script>
<script type="text/html" id="activity_status">
    {{# if(d.activity_status == 1){ }}
    <span style="color:#ec4758">未开始</span>

    {{# }else if(d.activity_status == 2){ }}
    <span style="color:#ec4758">报名中</span>
    {{# } else if(d.activity_status == 3){}}
    <span style="color:#ec4758">进行中</span>
    {{#} else { }}
    <span style="color:#ec4758">结束</span>

    {{# } }}
</script>
</body>
</html>